﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace WeChatParking.Core.Payment.WeixinPay
{
    
    /// <summary>
    ///统一下单请求实体
    /// </summary>
    public class WxpayUnifiedOrderRequest
    {

        /// <summary>
        /// 公众账号ID  appid  必填
        /// </summary> 
        [XmlElement("appid")]
        public string AppID { get;  set; }

        /// <summary>
        ///  商户号 mch_id 必填 
        /// </summary>  
        [XmlElement("mch_id")]
        public string MchID { get;  set; }

        /// <summary>
        /// 设备号 device_info 选填
        /// </summary> 
        [XmlElement("device_info")]
        public string DeviceInfo { get; set; }

        /// <summary>  
        /// 随机字符串 nonce_str 必填 
        /// </summary>
        [XmlElement("nonce_str")]
        public string NonceStr { get;  set; }
        /// <summary>
        /// 签名  sign 必填 
        /// </summary>
        [XmlElement("sign")]
        public string Sign { get;  set; }

        /// <summary>
        /// 商品描述 body  必填
        /// </summary> 
        [XmlElement("body")]
        public string Body { get; set; }

        /// <summary>
        /// 附加数据 attach  选填
        /// </summary> 
        [XmlElement("attach")]
        public string Attach { get; set; }

        /// <summary>
        /// 商户订单号 out_trade_no 必填
        /// </summary>  
        [XmlElement("out_trade_no")]
        public string OutTradeNo { get; set; }

        /// <summary>
        /// 总金额 total_fee 必填 单位为分
        /// </summary> 
        [XmlElement("total_fee")]
        public int TotalFee { get; set; }

        /// <summary>
        /// 终端 IP spbill_create_ip 必填 （订单生成的机器IP）
        /// </summary>  
        [XmlElement("spbill_create_ip")]
        public string SpBillCreateIp { get; set;}
        /// <summary>
        /// 交易起始时间  time_start 选填 格式 yyyyMMddhhmmss
        /// </summary> 
        [XmlElement("time_start")]
        public string TimeStart { get; set; }
        /// <summary>
        /// 交易失效时间  time_expire 选填 格式 yyyyMMddhhmmss
        /// </summary> 
        [XmlElement("time_expire")]
        public string TimeExpire { get; set; }
        /// <summary>
        /// 商品标记 goods_tag 选填 
        /// </summary> 
        [XmlElement("goods_tag")]
        public string GoodsTag { get; set; }
        /// <summary>
        /// 通知地址 notify_url 必填 
        /// </summary>  
        [XmlElement("notify_url")]
        public string NotifyUrl { get; set; }
        /// <summary>
        /// 交易类型 trade_type 必填  有三种类型：JSAPI,NATIVE,APP
        /// </summary> 
        [XmlElement("trade_type")]
        public string TradeType { get; set; }
        /// <summary>
        /// 用户标识  openid 选填 
        /// </summary>
        [XmlElement("openid")]
        public string OpenID { get; set; }

        /// <summary>
        /// 商品ID  product_id 选填 
        /// </summary> 
        [XmlElement("product_id")]
        public string ProductID { get; set; }

        public WxpayUnifiedOrderRequest()
        {
            AppID = WxpayConfig.AppID;
            MchID = WxpayConfig.MchID;
            NonceStr = WxpayHelper.GetNoncestr();
        }

        public IDictionary<string, string> GetParameters()
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("appid", this.AppID);
            parameters.Add("mch_id", this.MchID);
            parameters.Add("device_info", this.DeviceInfo);
            parameters.Add("nonce_str", this.NonceStr);
            parameters.Add("sign", this.Sign);
            parameters.Add("body", this.Body);
            parameters.Add("attach", this.Attach);
            parameters.Add("out_trade_no", this.OutTradeNo);
            parameters.Add("total_fee", this.TotalFee.ToString());
            parameters.Add("spbill_create_ip", this.SpBillCreateIp);
            parameters.Add("time_start", this.TimeStart);
            parameters.Add("time_expire", this.TimeExpire);
            parameters.Add("goods_tag", this.GoodsTag);
            parameters.Add("notify_url", this.NotifyUrl);
            parameters.Add("trade_type", this.TradeType);
            parameters.Add("openid", this.OpenID);
            parameters.Add("product_id", this.ProductID);
            return parameters;
        }

    }
}
